(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.FriendsListingView = (function(_super) {

    __extends(FriendsListingView, _super);

    function FriendsListingView() {
      this.afterLoad = __bind(this.afterLoad, this);
      return FriendsListingView.__super__.constructor.apply(this, arguments);
    }

    FriendsListingView.prototype.initialize = function() {
      FriendsListingView.__super__.initialize.apply(this, arguments);
      this.setElement("#main");
      this.model.bind("change", this.render);
      return this.model.fetch();
    };

    FriendsListingView.prototype.render = function() {
      var _this = this;
      return this.GetTemplate(SiteMap.Friends.FriendsListingEmptyTemplate, function(template) {
        $(_this.el).html(template(_this.model.toJSON()));
        _this.startLoading();
        return _this.renewScrolling();
      });
    };

    FriendsListingView.prototype.startLoading = function() {
      var _this = this;
      $(this.el).find("div").append("<div class='scroll-loading'></div>");
      this.isEnabled = false;
      return $.ajax({
        type: 'POST',
        url: this.model.url(),
        success: function(data) {
          _this.model.set("Page", _this.model.get("Page") + 1, {
            silent: true
          });
          _this.afterLoad(data);
          if (data.length) {
            return _this.isEnabled = true;
          }
        },
        complete: function() {
          return _this.removeScrollLoading();
        }
      });
    };

    FriendsListingView.prototype.afterLoad = function(data) {
      var _this = this;
      this.GetTemplate(SiteMap.Friends.FriendsListingTemplate, function(compiledTemplate) {
        $(_this.el).find("ul.friends-listing").append(compiledTemplate(data));
      });
    };

    return FriendsListingView;

  })(ScrollPagingView);

}).call(this);
